﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using MySql.Data.MySqlClient;
using Entities;
using DataAccess;

namespace BusinessFacade
{
    public class Busi_MessagePlanAudit
    {
        public DataTable MessagePlanAll() 
        {
            DataSet ds = DbHelperMySql.RunProcedure("MessagePlanLoad");
            return ds.Tables[0];
        }
        public DataTable MessagePlanName(mta_MessagePlanAudit_Model model)
        {
            MySqlParameter[] mp ={  
                                    new MySqlParameter("inputPlanName",MySqlDbType.VarChar,100)
                                 };
            mp[0].Value = model.InputPlanName;
            DataSet ds = DbHelperMySql.RunProcedure("MessagePlanName", mp);
            return ds.Tables[0];
        }
        public DataTable MessagePlanTemple(mta_MessagePlanAudit_Model model)
        {
            MySqlParameter[] mp ={  
                                    new MySqlParameter("planTemple",MySqlDbType.VarChar,100)
                                 };
            mp[0].Value = model.PalnTemplate;
            DataSet ds = DbHelperMySql.RunProcedure("MessagePlanBandTemple", mp);
            return ds.Tables[0];
        }
        public DataTable MessagePlanTwo(mta_MessagePlanAudit_Model model) 
        {
            MySqlParameter[] mp ={  
                                    new MySqlParameter("planTemple",MySqlDbType.VarChar,100),
                                    new MySqlParameter("inputPlanName",MySqlDbType.VarChar,100)
                                 };
            mp[0].Value = model.PalnTemplate;
            mp[1].Value = model.InputPlanName;
            DataSet ds = DbHelperMySql.RunProcedure("MessagePlanBandTwo", mp);
            return ds.Tables[0];
        }
        public DataTable ReadMessage(mta_MessagePlanAudit_Model model) 
        {
            MySqlParameter[] mp ={  
                                    new MySqlParameter("selectID",MySqlDbType.Int32)
                                 };
            mp[0].Value = model.PlanID;
            DataSet ds = DbHelperMySql.RunProcedure("MessagePlanRead", mp);
            return ds.Tables[0];
        }
        public int PassPlan(mta_MessagePlanAudit_Model model) 
        {
            string sql = "UPDATE nm_noteplan SET nm_noteplan.AuditingState = 1 WHERE planid = " + model.PlanID + ";";
            int result = DbHelperMySql.ExecuteSql(sql);
            return result;
        }
        public int ReturnPlan(mta_MessagePlanAudit_Model model)
        {
            string sql = "UPDATE nm_noteplan SET nm_noteplan.AuditingState = 2 WHERE planid = " + model.PlanID + ";";
            int result = DbHelperMySql.ExecuteSql(sql);
            return result;
        }
    }
}
